package com.gexiaobao.pigeon.app.util;

/**
 * 字节码转化十六进制
 *
 * @author xzb
 */
public class BytesToHex {

    /*
     *java二进制,字节数组,字符,十六进制,BCD编码转换2007-06-07 00:17/** */

    /**
     * 把16进制字符串转换成字节数组
     *
     * @param hex
     * @return
     */
    public static byte[] hexStringToByte(String hex) {
        int len = (hex.length() / 2);
        byte[] result = new byte[len];
        char[] achar = hex.toCharArray();
        for (int i = 0; i < len; i++) {
            int pos = i * 2;
            result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));
        }
//        System.out.println("hexStringToByte_start"+hex.toString());
        return result;
    }

    private static byte toByte(char c) {
        byte b = (byte) "0123456789ABCDEF".indexOf(c);
        return b;
    }

    public static void main(String[] args) {
        System.out.println(Integer.toHexString(0xFF & 15));
    }
}